package com.wc5818.controller;

import com.wc5818.service.WorkflowService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/workflow")
public class WorkflowController {
    @Autowired
    WorkflowService workflowService;

    @GetMapping("/deleteDeployment")
    public Object deleteDeployment(String id) {
        workflowService.deleteDeployment(id);
        return "ok";
    }

    @GetMapping("/myHistoryProcess")
    public Object myHistoryProcess(String processId) {
        return workflowService.historyActivityInstance(processId);
    }

    @GetMapping("/deployment")
    public Object deployment() {
        return workflowService.deployment("bpmn/loan.bpmn");
    }

    @GetMapping("/startNewProcess")
    public Object startNewProcess() {
        Map<String, Object> map = new HashMap<>();
        map.put("yewyId", 1);
        map.put("chesId", 2);
        map.put("yunyzxId", 3);
        map.put("fengkId", 3);
        map.put("cheyId", 3);
        map.put("chewId", 3);

        map.put("endProcess", false);
        map.put("chesReject2Yewy", false);
        map.put("yunyzxReject2Yewy", false);
        map.put("fengkzxReject2Yewy", false);

        return workflowService.startNewProcess("万车万融_贷款产品审核流程_003", map);
    }

    @GetMapping("/taskList")
    public Object taskList(String userId) {
        return workflowService.taskList(userId);
    }

    @GetMapping("/claim")
    public Object claim(String taskId, String userId) {
        return workflowService.claim(taskId, userId);
    }

    @GetMapping("/history")
    public Object history(String userId) {
        Map<String, Object> map = new HashMap<>();
        return workflowService.history(userId);
    }

    @GetMapping("/runWhere")
    public void getActivitiProccessImage(String pProcessInstanceId, HttpServletResponse response) throws Exception {
        workflowService.runWhere("", response);
    }

    @GetMapping("/deleteAllTask")
    public void deleteAllTask() throws Exception {
        workflowService.deleteAllTask("");
    }


}
